package com.infinit.easyreader.utils;

import android.util.Log;

/**
 * 类：LogUtil [V 1.0.0]
 * 包含类 : com.infinit.easyreader.utils.LogUtil
 * 作用：日志工具类
 * Created by rzy on 2016/1/29.
 */
public class LogUtil {
    /**
     * 常量：定义日志等级
     */
    public static final int LOG_LEVEL_INFO = 4;
    public static final int LOG_LEVEL_DEBUG = 3;
    public static final int LOG_LEVEL_VERBOSE = 5;
    public static final int LOG_LEVEL_WARN = 2;
    public static final int LOG_LEVEL_ERROR = 1;
    /**
     * LogUtil的唯一实例
     */
    public static LogUtil logUtil;

    private int currentLogLevel = 0;


    private LogUtil() {
    }

    /**
     * 作用：获取LogUtils的唯一实例
     */
    public static LogUtil newInstance() {

        if (logUtil == null) {
            synchronized (LogUtil.class) {
                if (logUtil == null) {
                    return new LogUtil();
                }
            }
        }
        return logUtil;
    }

    public void setCurrentLogLevel(int currentLogLevel) {
        this.currentLogLevel = currentLogLevel;
    }

    /**
     * 作用：打印DEBUG信息
     *
     * @param tag 标签
     * @param msg 信息
     */
    public void d(String tag, String msg) {
        if (currentLogLevel <= LOG_LEVEL_DEBUG) {
            Log.d(tag, msg);
        }
    }

    /**
     * 作用：打印Verbose信息
     *
     * @param tag 标签名
     * @param msg 信息实体
     */

    public void v(String tag, String msg) {
        if (currentLogLevel <= LOG_LEVEL_VERBOSE) {
            Log.v(tag, msg);
        }
    }


    /**
     * 作用：打印Info信息
     *
     * @param tag 标签名
     * @param msg 信息实体
     */

    public void i(String tag, String msg) {
        if (currentLogLevel <= LOG_LEVEL_INFO) {
            Log.i(tag, msg);
        }
    }


    /**
     * 作用：打印警告信息
     *
     * @param tag 标签名
     * @param msg 信息实体
     */

    public void w(String tag, String msg) {
        if (currentLogLevel <= LOG_LEVEL_WARN) {
            Log.w(tag, msg);
        }
    }


    /**
     * 作用：打印错误信息
     *
     * @param tag 标签名
     * @param msg 信息实体
     */

    public void e(String tag, String msg) {
        if (currentLogLevel <= LOG_LEVEL_ERROR) {
            Log.e(tag, msg);
        }
    }


}
